package Factory;

import java.util.Random;

import tree.Node;
import tree.TreeNodesManager;

/**
 * factory of boolean nodes (And,Or,Not,Big,Small,Equal)
 *
 */
public class BooleanNodesFactory {
	
	private BooleanBooleanSonsFactory booleanSonsFactory;
	private BooleanNumericSonsFactory numericSonsFactory;
	private Random random;
	
	
	
	
	
	public BooleanNodesFactory() {
		random=new Random();
		this.booleanSonsFactory=new BooleanBooleanSonsFactory();
		this.numericSonsFactory=new BooleanNumericSonsFactory();
	}
	public Node createRandomNode(Node parent, int depth, int maxDepth,TreeNodesManager treeNodesManager){
		Node randomNode;
		//can create either boolean sons or numeric sons
		if (depth+2<=maxDepth){
			//random between the 2 factories
			if (random.nextDouble()<0.5){
				randomNode = booleanSonsFactory.createRandomNode(parent, depth, maxDepth, treeNodesManager);
			}else{
				randomNode = numericSonsFactory.createRandomNode(parent, depth, maxDepth, treeNodesManager);
			}
		}else{
			//depth+2>maxDepth , can create only numeric sons
			randomNode = numericSonsFactory.createRandomNode(parent, depth, maxDepth, treeNodesManager);
		}
		
		return randomNode; 
	}
	
	public Node createRandomNumericSonsNode(Node parent, int depth
			, int maxDepth,TreeNodesManager treeNodesManager){
		return numericSonsFactory.createRandomNode(parent, depth, maxDepth, treeNodesManager);
	}
	
	public Node createRandomBooleanSonsNode(Node parent, int depth
			, int maxDepth,TreeNodesManager treeNodesManager){
		return booleanSonsFactory.createRandomNode(parent, depth, maxDepth, treeNodesManager);
	}
	
}
